-
Notifications
You must be signed in to change notification settings - Fork 48
: selection: bugfix reifying strided views #533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
shayne-fletcher
wants to merge
1
commit into
pytorch-labs:main
from
shayne-fletcher:export-D78315005
Closed
: selection: bugfix reifying strided views #533
shayne-fletcher
wants to merge
1
commit into
pytorch-labs:main
from
shayne-fletcher:export-D78315005
+116
−23
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This pull request was exported from Phabricator. Differential Revision: D78315005 |
shayne-fletcher
added a commit
to shayne-fletcher/monarch-1
that referenced
this pull request
Jul 15, 2025
Summary: **fix two bugs** thanks go to pzhan9 for reporting these issues! (see D78298712) (1) one in `reify_view` where views with strides were reified incorrectly. the old code assumed views could always be expressed as contiguous `range(start..start + len)` expressions, even when the view's stride differed from the base. this produced incorrect selections when the view was strided relative to the base layout. the fix is to recognize when a view is layout-aligned; that is, when each of its strides is an integer multiple of the corresponding base stride, including the unitary case; and to reify such views using `Range(start, Some(end), step)` expressions that preserve both shape and layout. previously, only the unitary case (`step` = 1) was handled. this change extends support to non-unitary aligned views, such as `step` = 2, by correctly computing the step factor and corresponding end coordinate. if any dimension is not layout-aligned — that is, if `view_stride` % `base_stride` ≠ 0 — we conservatively fall back to enumerating all selected coordinates explicitly. (2) also fixes a bug in `Shape::select()` where the length of a strided range was computed using truncating division. this now correctly uses ceiling division to ensure all selected indices are included. Differential Revision: D78315005
ea6ee56
to
48be0fe
Compare
This pull request was exported from Phabricator. Differential Revision: D78315005 |
1 similar comment
This pull request was exported from Phabricator. Differential Revision: D78315005 |
48be0fe
to
1d12586
Compare
Summary: **fix two bugs** thanks go to pzhan9 for reporting these issues! (see D78298712) (1) one in `reify_view` where views with strides were reified incorrectly. the old code assumed views could always be expressed as contiguous `range(start..start + len)` expressions, even when the view's stride differed from the base. this produced incorrect selections when the view was strided relative to the base layout. the fix is to recognize when a view is layout-aligned; that is, when each of its strides is an integer multiple of the corresponding base stride, including the unitary case; and to reify such views using `Range(start, Some(end), step)` expressions that preserve both shape and layout. previously, only the unitary case (`step` = 1) was handled. this change extends support to non-unitary aligned views, such as `step` = 2, by correctly computing the step factor and corresponding end coordinate. if any dimension is not layout-aligned — that is, if `view_stride` % `base_stride` ≠ 0 — we conservatively fall back to enumerating all selected coordinates explicitly. (2) also fixes a bug in `Shape::select()` where the length of a strided range was computed using truncating division (symptom: a strided `select()` like `0..7 step 2` gives sizes: `[3]`, but the selected indices are clearly `[0, 2, 4, 6]` i.e. 4 elements). this now correctly uses ceiling division to ensure all selected indices are included. Reviewed By: pzhan9 Differential Revision: D78315005
1d12586
to
c324978
Compare
This pull request was exported from Phabricator. Differential Revision: D78315005 |
This pull request has been merged in d327838. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
fix two bugs
thanks go to pzhan9 for reporting these issues! (see D78298712)
(1) one in
reify_view
where views with strides were reified incorrectly. the old code assumed views could always be expressed as contiguousrange(start..start + len)
expressions, even when the view's stride differed from the base. this produced incorrect selections when the view was strided relative to the base layout.the fix is to recognize when a view is layout-aligned; that is, when each of its strides is an integer multiple of the corresponding base stride, including the unitary case; and to reify such views using
Range(start, Some(end), step)
expressions that preserve both shape and layout. previously, only the unitary case (step
= 1) was handled. this change extends support to non-unitary aligned views, such asstep
= 2, by correctly computing the step factor and corresponding end coordinate.if any dimension is not layout-aligned — that is, if
view_stride
%base_stride
≠ 0 — we conservatively fall back to enumerating all selected coordinates explicitly.(2) also fixes a bug in
Shape::select()
where the length of a strided range was computed using truncating division. this now correctly uses ceiling division to ensure all selected indices are included.Differential Revision: D78315005